package com.xfdmao.fcat.gate.controller;

import com.alibaba.fastjson.JSONObject;
import com.xfdmao.fcat.api.vo.authority.SessionInfo;
import com.xfdmao.fcat.common.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: session验证只能在fcat-gate完成，如果跳转到fcat-user，fcat-user无法获取cookie
 * @author chenchen
 * @date 2018/7/11 19:27
 */
@RestController
public class SessionValidateController {
    private Logger logger = LoggerFactory.getLogger(SessionValidateController.class);

    @Autowired
    protected HttpServletRequest request;

    @RequestMapping(value = "/v1/session/sessionInfo", method = RequestMethod.GET)
    public JSONObject sessionUserInfo()throws Exception{
        try {
            logger.debug("sessionId:{}" ,request.getSession().getId());
            SessionInfo sessionInfo  = (SessionInfo) request.getSession().getAttribute("sessionInfo");
            logger.info("FCat:sessionInfo:{}",sessionInfo);
            return JsonUtil.getSuccessJsonObject(sessionInfo);
        }catch ( Exception e){
            e.printStackTrace();
        }
        return JsonUtil.getFailJsonObject();
    }
}
